using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Google.GData.Photos;
using Google.GData.Extensions.MediaRss;
using Google.Picasa;

namespace BloggerImageConversion
{
	/// <summary>
	/// Summary description for NewAlbumDialog.
	/// </summary>
	public class NewAlbumDialog : System.Windows.Forms.Form
    {
        private PicasaService service;
        private PicasaFeed feed;
        private PicasaEntry newEntry = null;
        private System.Windows.Forms.RadioButton AlbumPublic;
        private System.Windows.Forms.RadioButton AlbumPrivate;
        private Infragistics.Win.Misc.UltraButton Ok;
        private Infragistics.Win.Misc.UltraButton Cancel;
        private Infragistics.Win.UltraWinEditors.UltraCheckEditor AllowComments;
        private Infragistics.Win.UltraWinEditors.UltraTextEditor AlbumName;
        private Infragistics.Win.UltraWinEditors.UltraTextEditor AlbumDescription;
        private Infragistics.Win.UltraWinEditors.UltraTextEditor AlbumLocation;
        private Infragistics.Win.UltraWinEditors.UltraTextEditor AlbumKeywords;
        private Infragistics.Win.Misc.UltraLabel ultraLabel1;
        private Infragistics.Win.Misc.UltraLabel ultraLabel2;
        private Infragistics.Win.Misc.UltraLabel ultraLabel3;
        private Infragistics.Win.Misc.UltraLabel ultraLabel4;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public NewAlbumDialog(PicasaService service, PicasaFeed feed)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            this.service = service;
            this.feed = feed;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
            Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
            this.AlbumPublic = new System.Windows.Forms.RadioButton();
            this.AlbumPrivate = new System.Windows.Forms.RadioButton();
            this.Ok = new Infragistics.Win.Misc.UltraButton();
            this.Cancel = new Infragistics.Win.Misc.UltraButton();
            this.AllowComments = new Infragistics.Win.UltraWinEditors.UltraCheckEditor();
            this.AlbumName = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
            this.AlbumDescription = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
            this.AlbumLocation = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
            this.AlbumKeywords = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
            this.ultraLabel1 = new Infragistics.Win.Misc.UltraLabel();
            this.ultraLabel2 = new Infragistics.Win.Misc.UltraLabel();
            this.ultraLabel3 = new Infragistics.Win.Misc.UltraLabel();
            this.ultraLabel4 = new Infragistics.Win.Misc.UltraLabel();
            ((System.ComponentModel.ISupportInitialize)(this.AllowComments)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumName)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumDescription)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumLocation)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumKeywords)).BeginInit();
            this.SuspendLayout();
            // 
            // AlbumPublic
            // 
            this.AlbumPublic.Checked = true;
            this.AlbumPublic.Location = new System.Drawing.Point(23, 131);
            this.AlbumPublic.Name = "AlbumPublic";
            this.AlbumPublic.Size = new System.Drawing.Size(87, 21);
            this.AlbumPublic.TabIndex = 5;
            this.AlbumPublic.TabStop = true;
            this.AlbumPublic.Text = "public";
            // 
            // AlbumPrivate
            // 
            this.AlbumPrivate.Location = new System.Drawing.Point(23, 159);
            this.AlbumPrivate.Name = "AlbumPrivate";
            this.AlbumPrivate.Size = new System.Drawing.Size(107, 20);
            this.AlbumPrivate.TabIndex = 6;
            this.AlbumPrivate.Text = "private";
            // 
            // Ok
            // 
            this.Ok.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.Ok.Location = new System.Drawing.Point(256, 172);
            this.Ok.Name = "Ok";
            this.Ok.Size = new System.Drawing.Size(75, 23);
            this.Ok.TabIndex = 10;
            this.Ok.Text = "&Ok";
            this.Ok.Click += new System.EventHandler(this.Ok_Click);
            // 
            // Cancel
            // 
            this.Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.Cancel.Location = new System.Drawing.Point(175, 172);
            this.Cancel.Name = "Cancel";
            this.Cancel.Size = new System.Drawing.Size(75, 23);
            this.Cancel.TabIndex = 11;
            this.Cancel.Text = "&Cancel";
            // 
            // AllowComments
            // 
            this.AllowComments.Location = new System.Drawing.Point(173, 132);
            this.AllowComments.Name = "AllowComments";
            this.AllowComments.Size = new System.Drawing.Size(120, 20);
            this.AllowComments.TabIndex = 12;
            this.AllowComments.Text = "Allow Comments?";
            // 
            // AlbumName
            // 
            this.AlbumName.Location = new System.Drawing.Point(133, 17);
            this.AlbumName.Name = "AlbumName";
            this.AlbumName.Size = new System.Drawing.Size(160, 21);
            this.AlbumName.TabIndex = 13;
            // 
            // AlbumDescription
            // 
            this.AlbumDescription.Location = new System.Drawing.Point(133, 44);
            this.AlbumDescription.Name = "AlbumDescription";
            this.AlbumDescription.Size = new System.Drawing.Size(160, 21);
            this.AlbumDescription.TabIndex = 14;
            // 
            // AlbumLocation
            // 
            this.AlbumLocation.Location = new System.Drawing.Point(133, 71);
            this.AlbumLocation.Name = "AlbumLocation";
            this.AlbumLocation.Size = new System.Drawing.Size(160, 21);
            this.AlbumLocation.TabIndex = 15;
            // 
            // AlbumKeywords
            // 
            this.AlbumKeywords.Location = new System.Drawing.Point(133, 98);
            this.AlbumKeywords.Name = "AlbumKeywords";
            this.AlbumKeywords.Size = new System.Drawing.Size(160, 21);
            this.AlbumKeywords.TabIndex = 16;
            // 
            // ultraLabel1
            // 
            appearance5.TextHAlignAsString = "Right";
            this.ultraLabel1.Appearance = appearance5;
            this.ultraLabel1.Location = new System.Drawing.Point(-2, 21);
            this.ultraLabel1.Name = "ultraLabel1";
            this.ultraLabel1.Size = new System.Drawing.Size(129, 23);
            this.ultraLabel1.TabIndex = 17;
            this.ultraLabel1.Text = "Name of the Album:";
            // 
            // ultraLabel2
            // 
            appearance6.TextHAlignAsString = "Right";
            this.ultraLabel2.Appearance = appearance6;
            this.ultraLabel2.Location = new System.Drawing.Point(-2, 48);
            this.ultraLabel2.Name = "ultraLabel2";
            this.ultraLabel2.Size = new System.Drawing.Size(129, 23);
            this.ultraLabel2.TabIndex = 18;
            this.ultraLabel2.Text = "Description:";
            // 
            // ultraLabel3
            // 
            appearance7.TextHAlignAsString = "Right";
            this.ultraLabel3.Appearance = appearance7;
            this.ultraLabel3.Location = new System.Drawing.Point(-2, 75);
            this.ultraLabel3.Name = "ultraLabel3";
            this.ultraLabel3.Size = new System.Drawing.Size(129, 23);
            this.ultraLabel3.TabIndex = 19;
            this.ultraLabel3.Text = "Location:";
            // 
            // ultraLabel4
            // 
            appearance8.TextHAlignAsString = "Right";
            this.ultraLabel4.Appearance = appearance8;
            this.ultraLabel4.Location = new System.Drawing.Point(-2, 102);
            this.ultraLabel4.Name = "ultraLabel4";
            this.ultraLabel4.Size = new System.Drawing.Size(129, 23);
            this.ultraLabel4.TabIndex = 20;
            this.ultraLabel4.Text = "Keywords:";
            // 
            // NewAlbumDialog
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(343, 207);
            this.Controls.Add(this.ultraLabel4);
            this.Controls.Add(this.ultraLabel3);
            this.Controls.Add(this.ultraLabel2);
            this.Controls.Add(this.ultraLabel1);
            this.Controls.Add(this.AlbumKeywords);
            this.Controls.Add(this.AlbumLocation);
            this.Controls.Add(this.AlbumDescription);
            this.Controls.Add(this.AlbumName);
            this.Controls.Add(this.AllowComments);
            this.Controls.Add(this.Cancel);
            this.Controls.Add(this.Ok);
            this.Controls.Add(this.AlbumPrivate);
            this.Controls.Add(this.AlbumPublic);
            this.Name = "NewAlbumDialog";
            this.Text = "Create a new Album:";
            ((System.ComponentModel.ISupportInitialize)(this.AllowComments)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumName)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumDescription)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumLocation)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.AlbumKeywords)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
		#endregion

        private void Cancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void Ok_Click(object sender, System.EventArgs e)
        {
            Album acc = new Album();
            acc.Title = this.AlbumName.Text;
            acc.Summary = this.AlbumDescription.Text;
            if (this.AlbumLocation.Text.Length > 0) 
            {
                acc.Location = this.AlbumLocation.Text;
            }
            if (this.AlbumKeywords.Text.Length > 0) 
            {
                acc.PicasaEntry.Media = new MediaGroup();
                MediaKeywords keywords = new MediaKeywords(this.AlbumKeywords.Text);
                acc.PicasaEntry.Media.Keywords = keywords;
            }
            acc.Access = this.AlbumPublic.Checked ? "public" : "private";
            acc.CommentingEnabled = this.AllowComments.Checked;

            this.newEntry = this.service.Insert(this.feed, acc.PicasaEntry); 
            this.Close();

        }

        private void AlbumName_TextChanged(object sender, System.EventArgs e)
        {
            verifyOk();
        }

        private void AlbumDescription_TextChanged(object sender, System.EventArgs e)
        {
            verifyOk();
        }

        private void verifyOk()
        {
            this.Ok.Enabled = (this.AlbumName.Text.Length > 0 && this.AlbumDescription.Text.Length > 0);
        }

        public PicasaEntry CreatedEntry
        {
            get
            {
                return this.newEntry;
            }
        }


        }

       
       
	
}
